import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class HelloWorldJob {

    public static void main(String[] args) {
        try {
            Job job = Job.getInstance();
          //  job.setJobName("hello world job");
            job.setJarByClass(HelloWorldJob.class);

            //设置map reduce 类
            job.setMapperClass(HelloWorldMapper.class);
            job.setReducerClass(HelloWorldReduce.class);

            //设置数据输入 输出
            //根据core-default.xml配置是使用各种文件系统
            FileInputFormat.addInputPath(job, new Path(args[0]));
            FileOutputFormat.setOutputPath(job, new Path(args[1]));

            //设置数据输出格式
            job.setOutputKeyClass(Text.class);
            job.setOutputValueClass(IntWritable.class);

            System.exit(job.waitForCompletion(true) ? 0 : 1);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
